package com.oa.item.biz;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.oa.item.dao.PlanMapper;
import com.oa.item.entity.Plan;

import io.goeasy.GoEasy;

@Service
public class PlanBiz {
	@Resource
	private PlanMapper planDao;
	
	public Plan selectByPlanName(String planName){
		return planDao.selectByPlanName(planName);
	}
	
	public List<Plan> selectAllPlan(){
		return planDao.selectAllPlan();
	}
	
	public void checkedItem(){
		List<Plan> planList=planDao.selectAllPlan();
		Date nowTime = new Date();
		for (Plan plan : planList) {
			Date starTime=plan.getStarTime();
			Date endTime=plan.getEndTime();
			long nowToStar = starTime.getTime()-nowTime.getTime();
			long nowToEnd=endTime.getTime()-nowTime.getTime();
			if(nowToStar>0&&nowToStar>(6*24*60*60*1000)&&nowToStar<(7*24*60*60*1000)){
				GoEasy goEasy=new GoEasy("BC-26b9ed2ac7364785a09e1242e978bf47");
		        goEasy.publish("plan","距离"+plan.getPlanName()+"开始还有一周时间");
			}else if(nowToEnd>0&&nowToEnd>(6*24*60*60*1000)&&nowToEnd<(7*24*60*60*1000)){
				GoEasy goEasy=new GoEasy("BC-26b9ed2ac7364785a09e1242e978bf47");
		        goEasy.publish("plan","距离"+plan.getPlanName()+"开始还有一周时间");
			}
		}
		
	}
}
